<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增库区设置')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-reservoir-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">库区编码：</label>
                <div class="col-sm-8">
                    <input id="reservoirCode" name="reservoirCode" class="form-control" type="text" maxlength="16" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">库区名称：</label>
                <div class="col-sm-8">
                    <input name="reservoirName" class="form-control" type="text" maxlength="30" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">所属仓库：</label>
                <div class="col-sm-8">
                    <select id="warehouseId" name="warehouseId" class="form-control" required>
                        <option value="">请选择</option>
                    </select>
                    <!--<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>-->
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control" maxlength="200"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />

    <script th:inline="javascript">
        var prefix = ctx + "wh/reservoir"

        $(function () {
            //初始化仓库设置
            getWarehouseList();
        });

        $("#form-reservoir-add").validate({
            onkeyup: false,
            rules:{
                reservoirCode:{
                    minlength: 2,
                    maxlength: 16,
                    remote: {
                        url: prefix + "/checkReservoirCodeUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "reservoirCode": function() {
                                return $.common.trim($("#reservoirCode").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
            },
            messages: {
                "reservoirCode": {
                    remote: "库区编码已存在"
                },
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-reservoir-add').serialize());
            }
        }

        /**
         * 获取仓库设置下拉框信息
         */
        var warehousePrefix = ctx + "wh/warehouse"
        function getWarehouseList(){
            var data = {};
            var config = {
                url: warehousePrefix + "/ajaxList",
                type: "post",
                dataType: "json",
                data: data,
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                },
                success: function(result) {
                    //console.log(result)
                    if (result.code == web_status.SUCCESS) {
                        var str="";
                        $.each( result.data,function(index,value){
                            str+='<option value="'+value.id+'">'+value.warehouseCode+'---'+value.warehouseName+'</option>';
                        });
                        $('#warehouseId').append(str);
                    }else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                }

            };
            $.ajax(config)
        }

    </script>
</body>
</html>